package com.cj.demo;

import okhttp3.*;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

/**
 * @author cc
 * @date 2025-05-12 15:58
 **/

public class OkHttpDemo {


    public static void main(String[] args) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();

                builder.setConnectTimeout$okhttp(5000);
                builder.setReadTimeout$okhttp(5000);

        OkHttpClient client = builder.build();


        Request request = new Request.Builder().get().url("http://www.baidu.com").build();

        Call call = client.newCall(request);
        System.out.println("call = " + call);


        call.enqueue(new Callback() {
            @Override
            public void onFailure(@NotNull Call call, @NotNull IOException e) {

            }

            @Override
            public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
                System.out.println(response+"response");
                System.out.println(response.body().string());
            }
        });

    }
}
